home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / PolyFrog / PolyFrogViewPart.m < prev    next >
Text File  |  1994-05-04  |  2KB  |  121 lines

  1. #import "PolyFrogViewPart.h"
  2. #import "Thinker.h"
  3. #import <appkit/NXImage.h>
  4. #import <appkit/Window.h>
  5. #import <appkit/Panel.h>                // for NXRunAlertPanel()
  6. #import <dpsclient/wraps.h>
  7. #import <libc.h>
  8. #import <math.h>
  9.  
  10. @implementation PolyFrogView
  11.  
  12. - oneStep
  13. {
  14.   float mx, my;
  15.   float xi, yi;
  16.  
  17.   pp=p; p=n;
  18.   n=(n+1)%(NUMLINES-1);
  19.  
  20.   erasepp=erasep; erasep=erase;
  21.   erase=(n-lper); if(erase<0) erase+=(NUMLINES-1);
  22.  
  23.   PScurrentmouse(winNum, &mx, &my);
  24.   xi=((mx-midx)/urx)*10.0;
  25.   yi=((my-midy)/ury)*10.0;
  26.  
  27.   if((count++>500) && (((mx != oldx) && (my != oldy)) || (count>30000))){
  28.     count=0;
  29.     PSsetgray(0.0);
  30.     NXRectFill(&bounds);
  31.   }
  32.   oldx=mx; oldy=my;
  33.  
  34.   t1[n]=t1[p]+0.2*xi; if(t1[n]>(2*PI)) t1[n]-=(2*PI);
  35.   t2[n]=t2[p]+0.2*yi; if(t2[n]>(2*PI)) t2[n]-=(2*PI);
  36.   t3[n]=t3[p]+0.01;   if(t3[n]>(2*PI)) t3[n]-=(2*PI);
  37.  
  38.   x1[n]=(cos(t1[n])*s1) + (cos(t2[n])*s3) + midx;
  39.   yc1[n]=(sin(t1[n])*s2) + (sin(t2[n])*s4) + midy;
  40.  
  41.   PSsetrgbcolor(0.0,0.0,0.0);
  42.  
  43.   PSnewpath();
  44.   PSmoveto(x1[erasepp], yc1[erasepp]);
  45.   PSlineto(x1[erasep], yc1[erasep]);
  46.   PSlineto(x1[erase], yc1[erase]);
  47.   PSclosepath();
  48.   PSstroke();
  49.  
  50.   PSsetrgbcolor((cos(t1[n])+1.0)/2.0,
  51.                 (cos(t2[n])+1.0)/2.0,
  52.                 (cos(t3[n]*1.5)+1.0)/2.0);
  53.  
  54.   PSnewpath();
  55.   PSmoveto(x1[pp], yc1[pp]);
  56.   PSlineto(x1[p], yc1[p]);
  57.   PSlineto(x1[n], yc1[n]);
  58.   PSclosepath();
  59.   PSstroke();
  60.  
  61.   return self;
  62. }
  63.  
  64. - initFrame:(NXRect *)frameRect
  65. {
  66.   [super initFrame:frameRect];
  67.   [self newSize];
  68.   winNum=[[self window] windowNum];
  69.   return self;
  70. }
  71.  
  72. - sizeTo:(NXCoord)width :(NXCoord)height
  73. {
  74.   [super sizeTo:width :height];
  75.   [self newSize];
  76.   return self;
  77. }
  78.  
  79. - newSize
  80. {
  81.   int jkl;
  82.   urx=bounds.size.width;
  83.   ury=bounds.size.height;
  84.   
  85.   midx=urx/2;
  86.   midy=ury/2;
  87.  
  88.   n = 0;
  89.   t = 0;
  90.   
  91.   // phases of the three points;
  92.   p1=0;
  93.   p2=(4*PI)/3;
  94.   p3=(2*PI)/3;
  95.   
  96.   // starting angle of each point;
  97.   t1[0]=0;
  98.   t2[0]=p2;
  99.   t3[0]=p3;
  100.  
  101.   for(jkl=0;jkl<NUMLINES;jkl++){
  102.     x1[jkl]=midx;
  103.     yc1[jkl]=midy;
  104.   }
  105.  
  106.   // s1 and s2 should define an oval that takes up middle 75% of the screen
  107.   s1 = midx*0.5; s2 = midy*0.5;
  108.   s3 = midx*0.5; s4 = midy*0.5;
  109.  
  110.   // line per is the percentage back that erase steps
  111.   lper=NUMLINES-5;
  112.  
  113.   n=lper;
  114.   p=n-1;
  115.   pp=p-1;
  116.   count=0;
  117.   return self;
  118. }
  119.  
  120. @end
  121.